public class Tool {

    private static final String DATE_REGEX = "\\d{4}-\\d{2}-\\d{2}";


    public double getRemaining(){
        return Double.parseDouble(MainWindow.remainingLabel.getText().substring(5));
    }
    public double getExpense(){
        return Double.parseDouble(MainWindow.expenseLabel.getText().substring(5));
    }

    public double getTodayExpense(){
        return Double.parseDouble(MainWindow.todayExpenseLabel.getText().substring(7));
    }
    public void updateMainWindowData1(double incomeAmount) {
        // 获取当前主窗口数据
        double remaining = getRemaining();

        // 更新数据
        remaining += incomeAmount;

        // 更新主窗口显示
        MainWindow.remainingLabel.setText("本月剩余：" + remaining);

    }

    public void updateMainWindowData2(double expenseAmount) {
        // 获取当前主窗口数据
        double remaining = getRemaining();
        double expense = getExpense();
        double todayExpense = getTodayExpense();

        // 更新数据
        remaining -= expenseAmount;
        expense += expenseAmount;
        todayExpense += expenseAmount;

        // 更新主窗口显示
        MainWindow.remainingLabel.setText("本月剩余：" + remaining);
        MainWindow.expenseLabel.setText("本月消费：" + expense);
        MainWindow.todayExpenseLabel.setText("今日消费金额：" + todayExpense);
    }

    public void updateMainWindowData3(double expenseAmount) {
        // 获取当前主窗口数据
        double remaining = getRemaining();
        double expense = getExpense();
        double todayExpense = getTodayExpense();

        // 更新数据
        remaining += expenseAmount;
        expense -= expenseAmount;
        todayExpense -= expenseAmount;

        // 更新主窗口显示
        MainWindow.remainingLabel.setText("本月剩余：" + remaining);
        MainWindow.expenseLabel.setText("本月消费：" + expense);
        MainWindow.todayExpenseLabel.setText("今日消费金额：" + todayExpense);

    }

    public void updateMainWindowData4(double incomeAmount) {
        // 获取当前主窗口数据
        double remaining = getRemaining();

        // 更新数据
        remaining -= incomeAmount;

        // 更新主窗口显示
        MainWindow.remainingLabel.setText("本月剩余：" + remaining);

    }

    public void updateMainWindowData5(double expenseAmount,double upAmount) {
        // 获取当前主窗口数据
        double remaining = getRemaining();
        double expense = getExpense();
        double todayExpense = getTodayExpense();

        // 更新数据
        remaining += upAmount;
        remaining -= expense;
        expense -= upAmount;
        expense += expenseAmount;
        todayExpense -= upAmount;
        todayExpense += expense;

        // 更新主窗口显示
        MainWindow.remainingLabel.setText("本月剩余：" + remaining);
        MainWindow.expenseLabel.setText("本月消费：" + expense);
        MainWindow.todayExpenseLabel.setText("今日消费金额：" + todayExpense);

    }

    public void updateMainWindowData6(double incomeAmount,double upAmount) {
        // 获取当前主窗口数据
        double remaining = getRemaining();

        // 更新数据
        remaining -= upAmount;
        remaining += incomeAmount;

        // 更新主窗口显示
        MainWindow.remainingLabel.setText("本月剩余：" + remaining);

    }

    public boolean isValidDate(String date) {
        return date.matches(DATE_REGEX);
    }



}
